﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;

using SourceGrid;
using iPdf.Properties;

namespace iPdf
{
    partial class TataGridBase<T>
    {
        #region Columns

        protected const int MaxTataColumnWidth = 10000;
        protected const int MinTataColumnWidth = 50;

        public class TataGridColumnInfo : TataGridColumn<T>
        {
            public TataGridColumnInfo(Grid grid, ColumnCreator<T> creator, ColumnUpdator updator)
                : base(grid, creator, updator)
            {
                grid.Columns.Insert(grid.Columns.Count, this);
            }
        }


        #region  Methods

        protected TataGridColumnInfo CreateColumn(int width, string name, string description, 
            TataGridColumnInfo.ColumnCreator<T> creator, TataGridColumnInfo.ColumnUpdator updator, bool sortable)
        {
            TataGridColumnInfo column = new TataGridColumnInfo(this, creator, updator);

            column.Width = width;
            if (width > 0)
            {
                column.AutoSizeMode = SourceGrid.AutoSizeMode.None;
            }
            column.MaximalWidth = MaxTataColumnWidth;
            column.MinimalWidth = MinTataColumnWidth;
            column.Name = name;
            column.Description = description;
            column.Sortable = sortable;

            return column;
        }

        protected TataGridColumnInfo CreateColumn(int width, string name, string description,
            TataGridColumnInfo.ColumnCreator<T> creator, TataGridColumnInfo.ColumnUpdator updator)
        {
            return CreateColumn(width, name, description, creator, updator, true);
        }

        protected virtual SourceGrid.Cells.ColumnHeader CreateColumnHeader(object value, string toolTip, bool sortable)
        {
            SourceGrid.Cells.ColumnHeader colHeader = new SourceGrid.Cells.ColumnHeader(value);
            colHeader.View.Font = gridFont;
            colHeader.AutomaticSortEnabled = sortable;

            if (!string.IsNullOrEmpty(toolTip))
            {
                colHeader.ToolTipText = toolTip;
                colHeader.AddController(new SourceGrid.Cells.Controllers.ToolTipText());
            }

            return colHeader;
        }

        protected void CreateColumnHeader(TataGridColumnInfo colInfo)
        {
            SourceGrid.Cells.ColumnHeader header =
                CreateColumnHeader(colInfo.Name, colInfo.Description, colInfo.Sortable);

            colInfo[0] = header;
        }

        protected virtual void InitializeColumns(){}

        #endregion

        #endregion
    }
}
